package com.rpcfx.transports;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpResponse;

public class NettyHttpClientHandler extends ChannelInboundHandlerAdapter {

    private ResponseFuture responseFuture;

    public void setResponseFuture(ResponseFuture responseFuture) {
        this.responseFuture = responseFuture;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        FullHttpResponse response = (FullHttpResponse) msg;
        ByteBuf buf = response.content();
        byte[] cs = new byte[buf.readableBytes()];
        buf.readBytes(cs);
        responseFuture.setSuccess(cs);
        buf.release();
    }
}
